package view;



import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;

public class MenuFrame extends JMenuBar {

	private static final long serialVersionUID = 1L;
	
	private JMenu fileMenu = new JMenu("File");
	private JMenu editMenu = new JMenu("Edit");
		
	private JMenuItem openItem = new JMenuItem("Open");
	private JMenuItem closeItem = new JMenuItem("Close");
	private JMenuItem quitItem = new JMenuItem("Quit");
	private JMenuItem cancelItem = new JMenuItem("Undo");
	private JMenuItem redoItem = new JMenuItem("Redo");
	private JMenuItem cutItem = new JMenuItem("Cut");
	private JMenuItem copyItem = new JMenuItem("Copy");
	private JMenuItem pasteItem = new JMenuItem("Paste");
	
	public MenuFrame(){
		
		// set shortcuts
		fileMenu.setMnemonic('F');
		editMenu.setMnemonic('E');
		openItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_DOWN_MASK));
		quitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, KeyEvent.CTRL_DOWN_MASK));
		cancelItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, KeyEvent.CTRL_DOWN_MASK));
		pasteItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, KeyEvent.CTRL_DOWN_MASK));
		copyItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_DOWN_MASK));
		cutItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, KeyEvent.CTRL_DOWN_MASK));
		redoItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Y, KeyEvent.CTRL_DOWN_MASK));
		
				
		// items pour le menu Fichier
		fileMenu.add(openItem);
		fileMenu.add(closeItem);
		fileMenu.add(quitItem);
				
		// items pour le menu Edition
		editMenu.add(cancelItem);
		editMenu.add(redoItem);
		editMenu.addSeparator();
		editMenu.add(cutItem);
		editMenu.add(copyItem);
		editMenu.add(pasteItem);
				
		add(fileMenu);
		add(editMenu);
		
	}
	
	public void addOpenMenuListener(ActionListener listener) {
		openItem.addActionListener(listener);
	}
	
	public void addCloseMenuListener(ActionListener listener) {
		closeItem.addActionListener(listener);
	}
	
	public void addQuitMenuListener(ActionListener listener) {
		quitItem.addActionListener(listener);
	}
	
	public void addCancelMenuListener(ActionListener listener) {
		cancelItem.addActionListener(listener);
	}
	
	public void addRedoMenuListener(ActionListener listener) {
		redoItem.addActionListener(listener);
	}
	
	public void addCopyMenuListener(ActionListener listener) {
		copyItem.addActionListener(listener);
	}
	
	public void addPasteMenuListener(ActionListener listener) {
		pasteItem.addActionListener(listener);
	}
	
	public void addCutMenuListener(ActionListener listener) {
		cutItem.addActionListener(listener);
	}
}

